package apiv1

import (
	"fmt"
	"github.com/dlclark/regexp2"
	"github.com/gin-gonic/gin"
	"go-shop-admin/pkg/e"
	"go-shop-admin/pkg/serializer"
	"go-shop-admin/pkg/zydhlog"
	"net/http"
)

func Tests(c *gin.Context) {
	str := c.Query("pwd")
	expr := `^(?![0-9a-zA-Z]+$)(?![a-zA-Z!@#$%^&*]+$)(?![0-9!@#$%^&*]+$)[0-9A-Za-z!@#$%^&*]{8,16}$`
	reg, err := regexp2.Compile(expr, 0)
	if err != nil {
		c.JSON(http.StatusOK, serializer.NewResponse(200, err.Error(), e.TipsNil, map[string]interface{}{
			"reg": reg,
		}))
		return
	}
	m, err := reg.FindStringMatch(str)
	if err != nil {
		res := m.String()
		c.JSON(http.StatusOK, serializer.NewResponse(200, err.Error(), e.TipsNil, map[string]interface{}{
			"m": res,
		}))
		return
	}

	if m != nil {
		res := m.String()
		fmt.Println(res)
		c.JSON(http.StatusOK, serializer.NewResponse(200, e.TipsNil, e.TipsNil, map[string]interface{}{
			"m": res,
		}))
		return
	}

	c.JSON(http.StatusOK, serializer.NewResponse(200, e.TipsNil, e.TipsNil, map[string]interface{}{
		"ret": "true",
		"reg": reg,
		"str": str,
	}))

}

func WriteZydhLog(c *gin.Context) {
	zydhlog.Info("this is info log")
	zydhlog.Warning("this is info log")
}
